﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Debugging.Form2
{
    public class CustomerDataContract : INotifyPropertyChanged
    {
        public CustomerDataContract() { }

        private string _firstName;
        public String FirstName
        {
            get { return _firstName; } 
            set 
            {
                if (value != _firstName)
                {
                    _firstName = value;
                    OnNotifyPropertyChanged(new PropertyChangedEventArgs("FirstName"));
                }
            } 
        }

        private string _lastName;
        public String LastName 
        {
            get { return _lastName; }
            set 
            {
                if (value != _lastName)
                {
                    _lastName = value;
                    OnNotifyPropertyChanged(new PropertyChangedEventArgs("LastName"));
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnNotifyPropertyChanged(PropertyChangedEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            PropertyChangedEventHandler handler = PropertyChanged;
            // Event will be null if there are no subscribers
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion
    }
}
